package com.sbs.gaoxinqutoilet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sbs.gaoxinqutoilet.R;
import com.sbs.gaoxinqutoilet.entity.AddNewBuildTypeEntity;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2018/7/19.
 * Time: 2018/7/19  15:01
 */

public class GaizaoTypeAdapter extends BaseAdapter {
    private Context context;
    private List<AddNewBuildTypeEntity> addnewshigtlist;
    private LayoutInflater inflater;

    public GaizaoTypeAdapter(Context context, List<AddNewBuildTypeEntity> addnewshigtlist) {

        this.context = context;
        this.addnewshigtlist = addnewshigtlist;
        inflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return addnewshigtlist==null?0:addnewshigtlist.size();
    }

    @Override
    public Object getItem(int i) {
        return addnewshigtlist.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertview, ViewGroup viewGroup) {
        ViewHolder vh=null;
        if (convertview==null){
            vh=new ViewHolder();
            convertview=inflater.inflate(R.layout.item_roster_buildtype_choose,viewGroup,false);

            vh.ivCheck=(ImageView) convertview.findViewById(R.id.iv_item_roster_check);
            vh.tvName=(TextView) convertview.findViewById(R.id.tv_show_roster_name);

            convertview.setTag(vh);



        }else {
            vh= (ViewHolder) convertview.getTag();
        }

        AddNewBuildTypeEntity rosterBean=addnewshigtlist.get(position);
        if (rosterBean.isSelected()){
            vh.ivCheck.setImageResource(R.drawable.rb_yes);
        }else {
            vh.ivCheck.setImageResource(R.drawable.rb_no);
        }

        vh.tvName.setText(rosterBean.getText());



        return convertview;
    }

    static class ViewHolder{
        ImageView ivCheck;
        TextView tvName;
    }
}
